
/**
 * ======================================
 * 本次系统的一些方法
 * author: sky52
 * file: common.js
 * date: 2022/7/11 0:22
 * ======================================
 */
import { PLATFORM_LIST } from '@/data/platform'
export function setLoginType(type) {
  return localStorage.setItem('site_type', type)
}
export function getLoginType() {
  return localStorage.getItem('site_type')
}
export function getLoginTypeName() {
  const type = getLoginType()
  console.log('获取网页类型', type)
  let text = '未知'
  const res = PLATFORM_LIST.filter(v => {
    return v.value === type + ''
  })
  console.log('查询结果', res)
  if (res.length > 0) {
    text = res[0].name
  }
  return text
}
export function getLoginTypeRouter() {
  const type = getLoginType()
  console.log('获取网页类型', type)
  let text = '/login'
  const res = PLATFORM_LIST.filter(v => {
    return v.value === type + ''
  })
  console.log('查询结果', res)
  if (res.length > 0) {
    text = text + '/' + res[0].router
  }
  return text
}
/**
 * 输出生日
 * @param {} idCard
 * @returns
 */
export function getBirth(idCard) {
  var birthday = ''
  if (idCard != null && idCard !== '') {
    if (idCard.length === 15) {
      birthday = '19' + idCard.slice(6, 12)
    } else if (idCard.length === 18) {
      birthday = idCard.slice(6, 14)
    }
    birthday = birthday.replace(/(.{4})(.{2})/, '$1-$2-')
  // 通过正则表达式来指定输出格式为:1990-01-01
  }
  return birthday
}

/**
 * 输出性别
 * @param {} idCard
 * @returns
 */
export function getSex(idCard) {
  if (!idCard) { return '' }
  var sexStr = ''
  if (parseInt(idCard.slice(-2, -1)) % 2 === 1) {
    sexStr = '男'
  } else {
    sexStr = '女'
  }
  return sexStr
}

/**
 * 获得当前时间字符串yyyy年mm月dd日
 * @returns
 */
export function getNowDateStr() {
  const date = new Date()
  const str = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
  return str
}
